package utstat.listeners;

import java.util.HashMap;
import java.util.Map;

import utstat.UtEvent;
import utstat.UtEventListener;
import static utstat.Type.*;
import static utstat.Weapon.*;

/**
 * 3 knife kills in a game
 */
public class BananaListener implements UtEventListener {

	private Map<String, Integer> knifeKills = new HashMap<String, Integer>();
	private int currentRound = -1;

	@Override
	public String getIntestingFact(String player) {
		return null;
	}

	@Override
	public void processEvent(UtEvent e) {

		if (e.getType() == kill && (e.getWeapon() == Knife || e.getWeapon() == KnifeThrown)) {
			if (e.getRound() != currentRound) {
				nextRound();
				currentRound = e.getRound();
			}

			increment(e, knifeKills);

			int stabs = knifeKills.get(e.getSrc());
			if (stabs > 0 && stabs % 3 == 0) {
				System.out.println(e.getSrc() + " is peeling the " + e.getEnemyTeam() + " team like bananas!");
			}
		}
	}

	private int increment(UtEvent e, Map<String, Integer> countMap) {
		Integer count = countMap.get(e.getSrc());
		if (count == null) count = 0;
		count++;
		countMap.put(e.getSrc(), count);
		return count;
	}

	private void nextRound() {
		knifeKills = new HashMap<String, Integer>();
	}

}
